//
//  TstAddressbookCell.swift
//  TstChat
//
//  Created by wanghui on 2018/5/10.
//  Copyright © 2018年 daerwei. All rights reserved.
//

import UIKit
import SnapKit

class TstAddressbookCell: UITableViewCell {

    //头像
    lazy var headimage: UIImageView = {
        let headImg = UIImageView.init()
        headImg.layer.cornerRadius = 5
        headImg.layer.masksToBounds = true
        contentView.addSubview(headImg)
        headImg.isUserInteractionEnabled = true
        headImg.backgroundColor = UIColor.clear
        headImg.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(imageClick)))
        return headImg
    }()
    
    //名称
    lazy var nameLabel: UILabel = {
        let nlabel = UILabel()
        nlabel.textAlignment = .left
        nlabel.numberOfLines = 1
        return nlabel
    }()
    
//    //标签
//    lazy var tagbutton: UIButton = {
//        let button = UIButton.init(type: .custom)
//        contentView.addSubview(button)
//        button.setTitle(NSLocalizedString("创始",comment:"创始"), for: .normal)
//        button.setTitleColor(UIColor.init(red: 81/225, green: 170/225, blue: 56/225, alpha: 1), for: .normal)
//        button.titleLabel?.font = UIFont.systemFont(ofSize: 12.0)
//        button.layer.cornerRadius = 12
//        button.layer.masksToBounds = true
//        button.layer.borderColor = UIColor.init(red: 81/225, green: 170/225, blue: 56/225, alpha: 1).cgColor
//        button.layer.borderWidth = 1
//        button.isHidden = true
//        button.titleEdgeInsets = UIEdgeInsets(top: 2, left: 5, bottom: 2, right: 5)
//    
//        return button
//    }()
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .gray
        //添加子view
        self.contentView.addSubview(headimage)
        self.contentView.addSubview(nameLabel)
//        self.contentView.addSubview(tagbutton)
//        self.backgroundColor = UIColor.white
        headimage.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(10)
            make.width.height.equalTo(40)
        }
        
        nameLabel.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalTo(headimage.snp.right).offset(10)
            make.width.lessThanOrEqualTo(UIScreen.main.bounds.size.width - (10+headimage.bounds.size.width+10) - 10)
            make.width.greaterThanOrEqualTo(50)
            make.height.equalTo(20)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    @objc func imageClick(){
        print("点击了头像");
    }
}
